﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.XCMG.Util;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 生产工位配置
    /// </summary>
    public partial class WorkshoStationSetting : BusEntity
    {
        /// <summary>
        /// 工位编号
        /// </summary>
        public string StationId { get; set; }

        /// <summary>
        /// 工序编号
        /// </summary>
        //public string ProcessId { get; set; }

        /// <summary>
        /// 配置组
        /// </summary>
        public string GroupCode { set; get; }

        /// <summary>
        /// 配置类型
        /// </summary>
        public string SettingType { set; get; }

        /// <summary>
        /// 配置项
        /// </summary>
        public string SettingItem { set; get; }

        /// <summary>
        /// 配置值
        /// </summary>
        public string SettingValue { set; get; }
    }

    public partial class WorkshoStationSetting : BusEntity
    {
        /// <summary>
        /// 所属工位
        /// </summary>
        public WorkshoStation Station { set; get; }

        /// <summary>
        /// 所属工序
        /// </summary>
        //public CraftStepProcess Process { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class WorkshoStationSettingTypeConfig : BusEntityTypeConfig<WorkshoStationSetting>, IEntityTypeConfiguration<WorkshoStationSetting>
    {
        public override void Configure(EntityTypeBuilder<WorkshoStationSetting> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Station).WithMany(o=>o.Settings).HasForeignKey(p => p.StationId);
            //builder.HasOne(p => p.Process).WithMany().HasForeignKey(p => p.ProcessId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.StationId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            //builder.Property(p => p.ProcessId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.GroupCode).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.SettingType).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.SettingItem).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.SettingValue).HasMaxLength(200).IsRequired();
            #endregion

            #region 备注
            builder.HasComment("生产工位配置");
            builder.Property(p => p.StationId).HasComment("工位编号");
            builder.Property(p => p.GroupCode).HasComment("配置组");
            //builder.Property(p => p.ProcessId).HasComment("工序编号");
            builder.Property(p => p.SettingType).HasComment("配置类型");
            builder.Property(p => p.SettingItem).HasComment("配置项");
            builder.Property(p => p.SettingValue).HasComment("配置值");
            #endregion

            #region 种子数据
            #endregion
        }
    }
}
